/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#chaxtjhkjl-chaxanniu").trigger('click'); 
		return false;
		}
	});
});
function getShijian(mrkaishisj,mrjieshusj){
	//按钮重置
	$('#chaxtjhkjl-chongzhianniu').click(function(){
		$('#chaxtjhkjl-xingmingsj').val('');
		$("#hkjl-kaishjsj").val(mrkaishisj);
		$("#hkjl-jieshusj").val(mrjieshusj);
		kaishisj=$("#hkjl-kaishjsj").val();
		jieshusj=$("#hkjl-jieshusj").val();
		xingmingsj=$('#chaxtjhkjl-xingmingsj').val();
		pageNumber=1;
		dwpanduan=false;
		getHuankuanjl();
	});
	//进入页面默认时间查询
	if(mrkaishisj!=null||dwkaishisj!='null'){
		if(dwxingmingsj!=''&&dwxingmingsj!='null'){
			xingmingsj=dwxingmingsj;
			$('#chaxtjhkjl-xingmingsj').val(dwxingmingsj);
		}else {
			xingmingsj='';
		}
		if(dwkaishisj!=''&&dwkaishisj!='null'){
			kaishisj=dwkaishisj;
			jieshusj=dwjieshusj;
			$('#hkjl-kaishjsj').val(kaishisj);
			$('#hkjl-jieshusj').val(jieshusj);
		}else{
			kaishisj=mrkaishisj;
			jieshusj=mrjieshusj;
		}
		if(pageNo!=null&&pageNo!='null'){
			pageNumber=pageNo;
		}
		getHuankuanjl();
	}
		
}
//查询按钮点击
$('#chaxtjhkjl-chaxanniu').click(function(){
	kaishisj=$("#hkjl-kaishjsj").val();
	jieshusj=$("#hkjl-jieshusj").val();
	xingmingsj=$('#chaxtjhkjl-xingmingsj').val();
	pageNumber=1;
	dwpanduan=false;
	getHuankuanjl();
});

var kaishisj='';
var jieshusj='';
var xingmingsj='';

var pageNumber=1;
var dingwei='';
var dwpanduan=true;
var dwhuankuanid='';
var pageNo='';
var dwkaishisj='';
var dwjieshusj='';
var dwxingmingsj='';
//定位信息获取
function getHuankuandw(prehuankuanid,prepageNo,prekaishisj,prejieshusj,prexingmingsj){
	if(prepageNo!='null'&&prehuankuanid!='null'){
	dwhuankuanid=prehuankuanid;
	pageNo=prepageNo;
	dwkaishisj=prekaishisj;
	dwjieshusj=prejieshusj;
	dwxingmingsj=prexingmingsj;
	}
}
function getHuankuanjl(){
	var totalNumber = 0;
	var params={
			'kaishisj':kaishisj,
		    'jieshusj':jieshusj,
		    'xingmingsj':xingmingsj,
		};
		$.ajax({
		    type:"POST",
		    url:"../chaxuntjhkjl/getCount",
		    data:params,
		    async:false,
		    success: function(data){
		    	if(data!=null) {
		    		totalNumber = data;
				}
		    	if(totalNumber==0){
					$("#chaxtjhkjl-tbneirong").css("display","none");
					$("#cxtj-hk-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
				}else{
					$("#chaxtjhkjl-tbneirong").css("display","block");
					$("#cxtj-hk-img").html("");
				}
			}
		});
	function creatHuankuanjl(name) {
		$('#chaxtj-hkjl-lb').html('');
	  	var container = $('#pagination-'+name);
	  	container.pagination({
	    dataSource:'../chaxuntjhkjl/getBypage?kaishisj='+kaishisj+'&jieshusj='+jieshusj+'&xingmingsj='+xingmingsj,
	    locator: 'entities',
	    pageSize: 12,
		showNavigator: true,
		pageNumber:pageNumber,
   	    formatNavigator: '共 <%= totalNumber %> 条',
	    totalNumber: totalNumber,
	    callback: function(data, pagination) {
	    	if(data!='') {
	    		 dwxingmingsj =$("#chaxtjhkjl-xingmingsj").val();
				var content = '';
				$(data).each(function(index,e){
					if(this.xingbie==1){
						var xingbie ="男";
					}else if(this.xingbie==2){
						var xingbie="女";
					}else {
						var xingbie ='';
					}
					if(this.nianling==null){
						var nianling='';
					}else if(this.nianlingdw==null){
						var nianling=this.nianling;
					}else{
						var nianling=this.nianling+this.nianlingdw;
					}
					content += '<tr id="hang'+this.id+'">'+
					'<td width="5%">'+(index+1)+'</td>'+
	                '<td width="10%">'+this.xingming+'</td>'+
	                '<td width="10%">'+xingbie+'</td>'+
	                '<td width="10%">'+nianling+'</td>'+
	                '<td width="13%">'+this.huankuanrq+'</td>'+
	                '<td width="14%" class="right">'+parseFloat(this.qianfeije).toFixed(2)+'</td>'+
	                '<td width="14%" class="right">'+parseFloat(this.youhuije).toFixed(2)+'</td>'+
	                '<td width="14%" class="right">'+parseFloat(this.huankuanje).toFixed(2)+'</td>'+
	                '<td width="10%" class="caoz-color" onclick=getHkxq('+this.id+','+pagination.pageNumber+')><span >详情</span></td>'+
	                '</tr>';
					//查询状态定位判断Fjh
					if(dwhuankuanid==this.id){
						dingwei=this.id;
	        		}
				});
				$('#chaxtj-hkjl-lb').html(content);
				//查询状态定位Fjh
	        	if(dingwei!=null&&dingwei!=''){
	 	        	$('#chaxtj-hkjl-lb').find('tr[id="hang'+dingwei+'"]').addClass('list-tr');
	        	}
				//点击查询按钮和重置按钮定位状态消失
	        	if(!dwpanduan){
	        		$('#chaxtj-hkjl-lb').find('tr[id="hang'+dingwei+'"]').removeClass('list-tr');
	       	 	}
	    	}
	    }
	  });
	  return container;
	}
	creatHuankuanjl('fenyhkjl');
	if(totalNumber <= 12) {
		$('#pagination-fenyhkjl').css('display','none');
	}else{
		$('#pagination-fenyhkjl').css('display','block');
	}
}

//详情点击进入
function getHkxq(preid,prepageNo){
	var predwxingmingsj =encodeURI(encodeURI(dwxingmingsj));
	$('.cxtj-neirk').load(path+ "/views/chaxun-tongji/chaxtj-hkjl-hkxq.jsp?ID="+preid+"&pageNo="+prepageNo+"&kaishisj="+kaishisj+"&jieshusj="+jieshusj+"&dwxingmingsj="+predwxingmingsj);
}